package net.falcon.data;

import net.falcon.FalconArena;
import net.falcon.Util;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;

public class PlayerUtil {

	
	
	public static Object getMetadata(String player, String key) {
		Player p = Bukkit.getPlayer(player);
		if (p == null) {
			Util.print("Looked for player '" + player + "', who does not exist...");
			return null;
		}
		return getMetadata(p, key);
	}
	
	public static Object getMetadata(Player p, String key) {
		Object o = p.getMetadata(key);
		if(o == null) {
			Util.print("Looked for metadata value '" + key + "', which does not exist.");
		}
		return o;
	}
	
	public static void setMetadata(String player, String key, Object value) {
		Player p = Bukkit.getPlayer(player);
		if (p == null) {
			Util.print("Looked for player '" + player + "', who does not exist...");
			return;
		}
		setMetadata(p, key, value);
	}
	
	public static void setMetadata(Player p, String key, Object value) {
		p.setMetadata(key, new FixedMetadataValue(FalconArena.instance, value));
	}
}
